package com.seal.yoyoshop.adminweb;

import com.seal.yoyoshop.bin.Top;
import com.seal.yoyoshop.service.TopService;
import com.seal.yoyoshop.service.impl.TopServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "TopOperateServlet", value = "/admin/topOperate")
public class TopOperateServlet extends HttpServlet {

    private TopService topService = new TopServiceImpl();

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        获取前端参数
        String operate = request.getParameter("operate");
        String goodsIdstr = request.getParameter("goodsId");
        int goodsId = Integer.parseInt(goodsIdstr);
        String topTypestr = request.getParameter("type");
        int topType = Integer.parseInt(topTypestr);
        if (operate.equals("join")){
            Top top = new Top(topType,goodsId);
            boolean isSuccess = topService.addTop(top);
            if(isSuccess)response.getWriter().append("ok");

        }else {
            Top top = new Top(topType,goodsId);
            boolean isSuccess = topService.deleteTop(top);
            if(isSuccess)response.getWriter().append("ok");
        }


    }

}
